import axios from "../utils/http";
import path from "./path";
import { useStore } from 'vuex'
import store from "../store/index.js";
const store1 = useStore()
axios.defaults.withCredentials = true;
//这里放所有api接口
const api = {

    //以下是订单的API接口
    getOrdersSession(){
        return axios.get(path.baseUrl + path.ordersSession );
    },
    setOrderSession(ordersForm){
        return axios.post(path.baseUrl + path.getOrdersSessionDemo, ordersForm);
    },
    getNewOrderForm(){
        return axios.get(path.baseUrl + path.getNewOrderForm);
    },
    payForm(){
        return axios.get(path.baseUrl + path.payForm);
    },
    getOrderList(){
        return axios.get(path.baseUrl + path.getOrderList);
    },
    handleSendOut(orderId){
        return axios.get(path.baseUrl + path.handleSendOut + '?orderid='+orderId);
    },
    getCategory(productId){
        return axios.get(path.baseUrl+path.getCategory+productId);
    },
    getItem(itemId){
        return axios.get(path.baseUrl+path.getItem+itemId);
    },
    putItem(itemId){
        return axios.get(path.baseUrl+path.putItem+itemId);
    },
    putCartItem(itemId){
        return axios.post(path.baseUrl+path.putCartItem+itemId);
    },
    getNewItemForm(){
        return axios.get(path.baseUrl+path.pullItem);
    },
    //这个方法是向后端存入keyWord对象
    getSearchResult(keyWord){
        return axios.get(path.baseUrl+path.setSearchResult+keyWord)
    },
    //这个方法是从后端根据keyWord对象来取ProductList的值
    getProductList(){
        return axios.get(path.baseUrl+path.getSearchResult)
    },
    getItemByNothing(){
        return axios.get(path.baseUrl+path.getItemByNothing)
    },
    setProductSession(productId){
        return axios.get(path.baseUrl+path.setProductSession+productId)
    },
    //以下是登录注册的逻辑
    loginHandle(username,password){
        return axios.get(path.baseUrl + path.loginHandle + '?username=' + username + '&password=' + password)
    },
    //添加到购物车
    addItemToCart(itemId){
        return axios.get(path.baseUrl + path.addItemToCart + '?workingItemId=' + itemId )
    },
    //获取购物车
    getCart(){
        return axios.get(path.baseUrl + path.getCart )
    }

}

export default api